import { defineStore } from "pinia"; 
import { OrgState } from "@/stores/interface";
import piniaPersistConfig from "@/stores/helper/persist";
import {getOrganizationTreeApi } from "@/api/modules/public";

export const useOraStore = defineStore({
  id: "geeker-ora",
  state: ():OrgState=>({
    oragnizationTreeAll:[], 
    oragnizationTreeOne:[],
    oragnizationTreeTwo:[],

  }),
  getters: {

  },
  actions: {
    
    // Set oragnization
		async setOrgsAll(level:number) {
      const { data } = await getOrganizationTreeApi({level:level}); 
      if(level==0){//获取所有节点
        this.oragnizationTreeAll=data;
      }
      if(level==1){//获取一级节点
        this.oragnizationTreeOne=data;
      }
      if(level==2){ //获取2节到部门
        this.oragnizationTreeTwo=data;
      }
      
    }
  },
  persist: piniaPersistConfig("geeker-ora")
});
